package com.cskaoyan.controller.admin;

import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.bean.MarketAd;
import com.cskaoyan.bean.param.BaseParam;
import com.cskaoyan.bean.param.CommonData;
import com.cskaoyan.service.admin.MarketAdService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author RXC
 * @date 2022/6/26 16:21
 */
@RestController
@RequestMapping("admin/ad")
public class AdminAdController {

    @Autowired
    MarketAdService marketAdService;

    /**
     * 分页显示广告内容
     * param page=1&limit=20&sort=add_time&WXUserIndexVo=desc
     */
    @RequiresPermissions(value = {"admin:ad:list","*"},logical = Logical.OR)
    @RequestMapping("list")
    public BaseRespVo list(String name, String content, BaseParam baseParam) {
        CommonData<MarketAd> marketAdCommonData = marketAdService.list(name, content, baseParam);
        return BaseRespVo.ok(marketAdCommonData);
    }

    /**
     * 删除广告
     * @param marketAd
     */
    @RequiresPermissions(value = {"admin:ad:delete","*"},logical = Logical.OR)
    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody MarketAd marketAd) {
        int delete = marketAdService.delete(marketAd);
        return BaseRespVo.ok();
    }

    /**
     * 创建广告
     * @param marketAd
     * @return  marketAd
     */
    @RequestMapping("create")
    public BaseRespVo create(@RequestBody MarketAd marketAd) {
        marketAd = marketAdService.create(marketAd);
        return BaseRespVo.ok(marketAd);
    }

    /**
     * 更新广告
     * @param marketAd
     * @return  marketAd
     */
    @RequiresPermissions(value = {"admin:ad:update","*"},logical = Logical.OR)
    @RequestMapping("update")
    public BaseRespVo update(@RequestBody MarketAd marketAd) {
        marketAd = marketAdService.update(marketAd);
        return BaseRespVo.ok(marketAd);
    }

}
